package cengxubianli

import "hufeng/ercahshu"

func maxDepth(root *ercahshu.TreeNode) int {
	ans := 0
	if root == nil {
		return ans
	}
	var dfs func(node *ercahshu.TreeNode, height int)
	dfs = func(node *ercahshu.TreeNode, height int) {
		if node == nil {
			return
		}
		ans = max(ans, height)
		if node.Left != nil {
			dfs(node.Left, height+1)
		}
		if node.Right != nil {
			dfs(node.Right, height+1)
		}
	}
	dfs(root, 1)
	return ans
}
